﻿using B.MESUI.Login.Properties;
using DevExpress.Accessibility;
using DevExpress.XtraPrinting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace B.MESUI.Login.BasicData_UI
{
    
    public class BaseMethod
    {
       public  async static Task<string> MethodsURL(  string method, string url, string jsonData="")
       {
           using(HttpClient client=new HttpClient())
           {
               client.BaseAddress=new Uri(Settings.Default.BaseUrl_SLY);
               HttpResponseMessage response = null;
               HttpContent content = null;
               switch (method.ToLower())
               {
                   case "get":
                       response = await client.GetAsync(url);
                       break;
                        case "post":
                            content = new StringContent(jsonData, Encoding.UTF8, "application/json");
                            response = await client.PostAsync(url, content);
                            break;
                        case "delete":
                        response = await client.DeleteAsync(url);
                            break;
                        case "put":
                        content = new StringContent(jsonData, Encoding.UTF8, "application/json");
                        response = await client.PutAsync(url, content);
                        break;
                        default:
                            break;
                }
              return response.Content.ReadAsStringAsync().Result;
           }
       }
    }
}
